﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DHQGHN.PM0.Common.Attributes;

namespace DHQGHN.PM0.Models.Admin
{
    public class MaritalStatusModel
    {
        public string Marital_Status_Id { get; set; }
        [Required(AllowEmptyStrings = false, ErrorMessageResourceName = "Error_HaventPutMaritalStatusCodeYet", ErrorMessageResourceType = typeof(Resources.Localization))]
        [Remote("CheckExistMaritalCode", "MaritalStatus", ErrorMessageResourceName = "MaritalStatusCodeExist", ErrorMessageResourceType = typeof(Resources.Localization), HttpMethod = "POST", AdditionalFields = "Marital_Status_Id")]
        [StringLength(12, ErrorMessageResourceName = "Error_MaritalStatusCodeLength", ErrorMessageResourceType = typeof(Resources.Localization))]
        [RegularExpression(@"^[a-zA-Z0-9]+[a-zA-Z0-9_]*[a-zA-Z0-9]*$", ErrorMessage = "Mã không đúng định dạng")]
        [LocalizationDisplay("MaritalStatusCode")]
        public string Code { get; set; }
        [Required(AllowEmptyStrings = false, ErrorMessageResourceName = "Error_HaventPutMaritalStatusNameYet", ErrorMessageResourceType = typeof(Resources.Localization))]
        [Remote("CheckExistMaritalName", "MaritalStatus", ErrorMessageResourceName = "MaritalStatusNameExist", ErrorMessageResourceType = typeof(Resources.Localization), HttpMethod = "POST", AdditionalFields = "Marital_Status_Id")]
        [StringLength(255, ErrorMessageResourceName = "Error_MaritalStatusNameLength", ErrorMessageResourceType = typeof(Resources.Localization))]        
        [LocalizationDisplay("MaritalStatusName")]
        public string Name { get; set; }
        [StringLength(255, ErrorMessageResourceName = "Error_MaritalStatusDescriptionsLength", ErrorMessageResourceType = typeof(Resources.Localization))]
        [LocalizationDisplay("MaritalStatusDescriptions")]
        public string Descriptions { get; set; }
        public int Deleted { get; set; }
        public int RecordCount { get; set; }
        public MaritalStatusModel()
        {

        }

        public MaritalStatusModel(DHQGHN.DAL.Models.Admin.MaritalStatusModel model)
        {
            this.Marital_Status_Id = model.Marital_Status_Id;
            this.Code = model.Code;
            this.Name = model.Name;
            this.Descriptions = model.Descriptions;
            this.RecordCount = model.RecordCount;
            this.Deleted = model.Deleted;
        }

        internal DHQGHN.DAL.Models.Admin.MaritalStatusModel toDALModel()
        {
            return new DAL.Models.Admin.MaritalStatusModel
            {
                Marital_Status_Id = this.Marital_Status_Id,
                Code = this.Code != null ? this.Code.Trim() : null,
                Name = this.Name != null ? this.Name.Trim() : null,
                Descriptions = this.Descriptions,
                Deleted = this.Deleted
            };
        }
    }
}